// pages/module/withdrawal/withdrawal.js
import shareFun from '../../../utils/shareFun.js';
import {
  cherckMineInfo,
  widthdraw,
  forecast,
  bank_query,
} from '../../../utils/imapi.js';
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    is_show_donate:false,
    donate:0.2,
    swiper_list:[
      {name:'*佳',price:'0.02'},
      {name:'阿斯頓*佳',price:'0.02'},
      {name:'*佳是的哇',price:'0.02'},
      {name:'*佳啊啊',price:'0.02'},
    ],
    donate_list:[
      {img:'/images/index/donate_bg.png',title:'助力四岁血癌移植娃',donated_price:'38000.00',target:'58000.00',my_donated:'0.02'},
      {img:'/images/index/donate_bg.png',title:'助力四岁血癌移植娃',donated_price:'38000.00',target:'58000.00',my_donated:'0.02'},
      {img:'/images/index/donate_bg.png',title:'助力四岁血癌移植娃',donated_price:'38000.00',target:'58000.00',my_donated:'0.02'},
      {img:'/images/index/donate_bg.png',title:'助力四岁血癌移植娃',donated_price:'38000.00',target:'58000.00',my_donated:'0.02'},
    ],
    balance:0,
    get_balance:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    /*const {data} = showDonat({})
    if(data == 1){
      this.setData({
        is_show_donate:true
      })
    }
    shareFun.hidenShareMenu()
    */

    // this.setData({
    //   balance:app.globalData.userInfo.balance
    // })
	
    const forecast_data= await forecast();
	
    this.setData({
      balance:forecast_data.data.balance
    })

  },

  get_all(e){

     this.setData({
      get_balance:this.data.balance
     })

  },

  inputEdit(e){

    let value=e.detail.value
    this.setData({
      get_balance:value
    })

  },

withdrawHandler: async function(e){
	
	if(this.data.balance!=this.data.get_balance){
		wx.showModal({
					title: '提示',
					content: '只支持提现所有',
					success: function(res) {
						
					}
				})
		return;
	}
	
	var res=await bank_query({page_index:1,page_size:10});
	console.log(res);
	
	if(res.data.length==0){
		wx.showModal({
					title: '提示',
					content: '您还没有绑定银行卡，请先去绑定',
					success: function(res) {
						if (res.confirm) {
							wx.navigateTo({
							  url: '/pages/module/setting/setting',
							})
						} else if (res.cancel) {
					
						}
					}
				})
		return;
	}
	
    var init=await cherckMineInfo();
    console.log(init.data.phone);
	
	if(!init.data.phone && !init.data.wechat_alian_no){
		wx.showModal({
					title: '提示',
					content: '您还没有绑定手机和微信号，请先去绑定',
					success: function(res) {
						if (res.confirm) {
							wx.navigateTo({
							  url: '/pages/module/setting/setting',
							})
						} else if (res.cancel) {
						//console.log('用户点击取消')
						}
					}
				})
		return;
	}
	
	if(!init.data.phone){
		wx.showModal({
					title: '提示',
					content: '您还没有绑定手机号，请先绑定手机号',
					success: function(res) {
						if (res.confirm) {
							wx.navigateTo({
							  url: '/pages/module/setting/setting',
							})
						} else if (res.cancel) {
						//console.log('用户点击取消')
						}
					}
				})
		return;
	}
	
	if(!init.data.wechat_alian_no){
		wx.showModal({
					title: '提示',
					content: '您还没有绑定微信号，请先绑定微信号',
					success: function(res) {
						if (res.confirm) {
							wx.navigateTo({
							  url: '/pages/module/setting/setting',
							})
						} else if (res.cancel) {
						//console.log('用户点击取消')
						}
					}
				})
		return;
	}
	
    if (this.data.get_balance > this.data.balance ){

      wx.showToast({
        title: '可提现余额不足，请重新输入',
      })
      return
    }


    if (this.data.get_balance==0 || this.data.balance==0){
      wx.showToast({
        title: ' 提现金额为0',
      })
      return
      
    }

    // 弹出提示
var that =this 
    wx.showModal({
      title: '提示',
      content: '确认提现？',
      cancelText:'取消',
      confirmText:'确定',
      confirmColor:'#F95A4B',
      async success (res) {
        if (res.confirm) {//确认
          
          
          console.log("确认");
        

          const {resdata}= await widthdraw({money:that.data.get_balance});
        
            // wx.showToast({
            //   title: '提现申请已提交，将在48小时内审核完成，节假日延时，请耐心等待',
            // })

            wx.showModal({
              title: '',
              content: '提现申请已提交，将在48小时内审核完成，节假日延时，请耐心等待',
              cancelText:'取消',
              confirmText:'确定',
              confirmColor:'#F95A4B',
              async success (res) {
                wx.navigateBack({
                  delta: -1,
                })
              }
            })

         
           

          
        } else if (res.cancel) {//取消
          
        }
      }
    })


  },


  go_accbill(){ //账单
    wx.navigateTo({
      url: './withdrawalRecord/withdrawalRecord',
    })
  },

  // 公益  暂时不用
  donateDetail(e){
    var index = e.currentTarget.dataset.index
    app.globalData.cur_donate = this.data.donate_list[index]
    wx.navigateTo({
      url: './donateDetail/donateDetail',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})